package service;

import base.BaseService;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.RowMapper;

import pojo.dishesType;

public class DishesTypeService extends BaseService {
	public class DishseTypeRowMapper implements RowMapper<dishesType> {
		
 	   public dishesType mapRow(ResultSet rs, int rownum) throws SQLException {
 
   dishesType inf = new dishesType();
	inf.setId(rs.getInt("id"));
	inf.setName(rs.getString("name"));
	return inf;
			}
    }
	public List<dishesType> getDishesType(){
		String sql = "SELECT * from dishes_type";
		return jdbcTemplate.query(sql,new DishseTypeRowMapper());
}
	public dishesType getTypeByid(int id){
		
		String sql="select * from dishes_type where id=?";
		dishesType inf=this.jdbcTemplate.queryForObject(sql, new DishseTypeRowMapper(),id);
		return inf;
	}
	public void getUpdateByid(String name,int id){
		
		String sql ="update dishes_type set name=? where id=?";
		
		 jdbcTemplate.update(sql,name,id);
		}
	 public int DeleteType(int id){
			
			String sql ="delete from dishes_type where id=?";
			
			return jdbcTemplate.update(sql,id);
			
	 }	
	 public int add(String name ){
			
			String sql ="insert into dishes_type set name=?";
			
			return jdbcTemplate.update(sql,name);
		}
}
